$(function() {
	$("#loading-first").fadeOut(500);
	var approval_leve1 = 1;
	var approval_leve2 = 1;
	var tab1Scroll = new IScroll('#tab1', {
		mouseWheel: true,
		disableMouse: true,
		disablePointer: true,
		scrollbars: 'custom',
		interactiveScrollbars: true,
	});
	var tab2Scroll = new IScroll('#tab2', {
		mouseWheel: true,
		disableMouse: true,
		disablePointer: true,
		scrollbars: 'custom',
		interactiveScrollbars: true,
	});
	$('.isapproval-process').on('click', function() {
		console.log(1);
		if($(this).find('input').prop('checked')) {
			$('.approval-process').css('display', 'block');
		} else {
			$('.approval-process').css('display', 'none');
		}

	});
	$('.add_approve_leve').on('click', function() {
		if($(this).data('tab') == 1) {
			approval_leve1++;
			addapprovel(1,approval_leve1);
		} else {
			approval_leve2++;
			addapprovel(2,approval_leve2);
		}
	});
	$('.back').on('click',function(){
		window.history.go(-1);
	})
	function addapprovel(type,leve){
			if(leve > 3) {
				Err('审批层次不能多于三层');
			} else {
				var addapprovelist1;
				var addapprove1;
				if(type==1){
					addapprovelist = $('.addapprovelist1').html();
					addapprove = $('.addapprove1').html();
				}else{
					addapprovelist = $('.addapprovelist2').html();
					addapprove = $('.addapprove2').html();
				}
				
				
				addapprove += `<div style="width:20px;height: 20px;background: #ccc;border-radius: 50%;"></div>
									<div style="margin: 2px 9px;background: #ccc;height: 100px;width:1px;"></div>`;
				addapprovelist += `<div style="height: 20px;font-size: 12px;line-height: 20px;font-weight: 900;">
										第${leve}级审批人
									</div>
									<div style="margin: 2px;height: 100px;">
										<div class="add-approve-people" style="width:100px;text-align: center;height: 30px;line-height: 25px;border: 1px solid #ccc;font-size: 12px;margin-bottom: 10px;">添加审批人</div>
										<div>
											<ul>
												
											</ul>
										</div>
									</div>`;
				if(type==1){
					$('.addapprovelist1').html(addapprovelist);
					$('.addapprove1').html(addapprove);
					tab1Scroll.refresh();
				}else{
					$('.addapprovelist2').html(addapprovelist);
					$('.addapprove2').html(addapprove);
					tab2Scroll.refresh();
				}
			}
	}
	
	$('.cartype li').on('click', function() {
		
		if($(this).find('div').css('display')=='block'){
			$(this).find('div').css('display', 'none');
		}else{
		$(this).find('div').css('display', 'block');
		}
	});
	$('.am-icon-close').on('click', function() {
		$(this).parent().remove();
	});
	$('.time_chang1').on('click', function(){
		opentimechang(1);
	});
	$('.time_chang2').on('click', function(){
		opentimechang(2);
	});
	$('input[name="usedate"]').on('change',function(){
		if($('input[name="usedate"]:checked').val()==1){
			$('input[name="use_start_date"]').prop('readonly',true);
			$('input[name="use_end_date"]').prop('readonly',true);
		}else{
			$('input[name="use_start_date"]').prop('readonly',false);
			$('input[name="use_end_date"]').prop('readonly',false);
		}
	});
	$('input[name="usedate2"]').on('change',function(){
		if($('input[name="usedate2"]:checked').val()==1){
			$('input[name="use_start_date2"]').prop('readonly',true);
			$('input[name="use_end_date2"]').prop('readonly',true);
		}else{
			$('input[name="use_start_date2"]').prop('readonly',false);
			$('input[name="use_end_date2"]').prop('readonly',false);
		}
	});
	$('input[name="quota"]').on('change',function(){
		if($('input[name="quota"]:checked').val()==1){
			$('input[name="money"]').prop('readonly',true);
		}else{
			$('input[name="money"]').prop('readonly',false);
		}
	})
	
	
	//改变用车日期
	function opentimechang(number){
		layer.open({
				type: 1,
				area: ['500px', '500px'],
				title: false,
				id: 'opentimechang'//防止重复弹出
					,
				content: $('.time_change_main').html(),
				btn: ['确认','取消'],
				yes: function() {
					if($('#opentimechang').find('.time_chang_ul').find('li[class="am-active"]').data('idx')==1){
						if(number==1){
							$('.time_type1').html('不限');
						}else{
							$('.time_type2').html('不限');
						}
					}else if($('#opentimechang').find('.time_chang_ul').find('li[class="am-active"]').data('idx')==2){
						var racheck=$('#opentimechang').find('#tab2').find('input[name="wordday"]:checked').val();
							var racheckmain1=$('#opentimechang').find('#tab2').find('input[name="wordday"]:checked').parent().parent().next().find('input[type="time"]').eq(0).val();
							var racheckmain2=$('#opentimechang').find('#tab2').find('input[name="wordday"]:checked').parent().parent().next().find('input[type="time"]').eq(1).val();
							if(racheck==1){
								timetypemain=`<div>
									<div>工作日 ${racheckmain1}-${racheckmain2}</div>
								</div>`;
							}else if(racheck==2){
								timetypemain=`<div>
									<div>节假日 ${racheckmain1}-${racheckmain2}</div>
								</div>`;
							}
						if(number==1){
							
							$('.time_type1').html(timetypemain);
						}else{
							$('.time_type2').html(timetypemain);
						}
					}else{
						var checkboxmain=`<div>`;
						for(var checkidx=0;checkidx<$('#opentimechang #tab3').find('input[type="checkbox"]').length;checkidx++){
							if($('#opentimechang #tab3').find('input[type="checkbox"]').eq(checkidx).prop('checked')){
								checkboxmain+=`<div>
								${$('#opentimechang #tab3').find('input[type="checkbox"]').eq(checkidx).val()} 
								${$('#opentimechang #tab3').find('input[type="checkbox"]').eq(checkidx).parent().parent().next().find('input[type="time"]').eq(0).val()}-
								${$('#opentimechang #tab3').find('input[type="checkbox"]').eq(checkidx).parent().parent().next().find('input[type="time"]').eq(0).val()}
								</div>`;
							}
						}
						checkboxmain+=`</div>`;
						console.log(checkboxmain);
						
						if(number==1){
							$('.time_type1').html(checkboxmain);
						}else{
							$('.time_type2').html(checkboxmain);
						}
					}
					layer.closeAll();
				},
				btn2: function() {
					layer.closeAll();
				},
				btnAlign: 'c' //按钮居中
					,
				shade: 0 //不显示遮罩
					
			});
	}
})